<?php
class ques_class {
	var $row=8;
	var $node=false;
	var $table_count=0;
	var $sql=false;
	function get_class_list(){
		global $user,$game_id,$server_id;
		//parent node:
		if($this->sql!=false) $sql=$this->sql;
		else {
			if(isset($_GET['sug']))$sql="select * from question_class where parent_id=0 and (property='bug' or property='advice') and game_id=$game_id   order by place";
			else $sql="select * from question_class where parent_id=0 and property='question' and game_id=$game_id   order by place";
		}
		$res=run_sql($sql,__LINE__);
		$row=mysql_fetch_array($res,1);
		$node['info']['count']=0;
		while ($row) {			
			$count=$node['info']['count'];
			$node[$count]['title']=$row['title']; // 主标题
			$node[$count]['id']=$row['class_id'];  //主标题id
			$node[$count]['property']=$row['property']; //属性 'bug' '建议'
			$node['info']['count']++;
			$row=mysql_fetch_array($res,1);
		}
		//end of parent.
		
		//childs node:
		$max_count=0;
		$count_row=0;
		for($i=0;$i<$node['info']['count'];$i++) {
			$parent_id=$node[$i]['id'];
			$sql="select * from question_class where parent_id='$parent_id' and game_id=$game_id   order by place";
			$res=run_sql($sql,__LINE__);
			$row=mysql_fetch_array($res,1);
			$node[$i]['list']['count']=0;
			while ($row) {
				$count=$node[$i]['list']['count'];
				$node[$i]['list'][$count]['title']=$row['title']; //子标题
				$node[$i]['list'][$count]['id']=$row['class_id']; //子标题
				$node[$i]['list']['count']++;
				$row=mysql_fetch_array($res,1);
			}
			if($i>=$count_row) {
				$max_count++;
				$count_row=$count_row+$this->row;
				$node['max'][$max_count]=0;
			}
			if($node[$i]['list']['count']>$node['max'][$max_count])
			$node['max'][$max_count]=$node[$i]['list']['count'];
		}
		$this->node=$node;
	}
	function get_assign_tpl(){
		if(!$this->node) $this->get_class_list();
		$this->table_count=ceil($this->node['info']['count']/$this->row);
	}
}
?>